Skip to content

Conversation

valeriosetti
Copy link
Contributor

Zephyr's long term goal for crypto support is to use only PSA API. This PR replaces usages of MD with proper PSA API for HMAC.

@valeriosetti valeriosetti force-pushed the ipv6-replace-legacy-crypto branch from cf232b7 to 6fd6589 Compare October 10, 2025 12:12
rlubos
rlubos previously approved these changes Oct 10, 2025
rlubos
rlubos previously approved these changes Oct 10, 2025
jukkar
jukkar previously approved these changes Oct 10, 2025
@valeriosetti
Copy link
Contributor Author

Failing CI tests are due to Mbed TLS not properly sizing the internal buffer for PSA keys (MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE). I will check with Mbed TLS developers if we can fix this directly in Mbed TLS instead of adding a fix in Zephyr.

@valeriosetti valeriosetti dismissed stale reviews from jukkar and rlubos via c723984 October 13, 2025 07:59
Copy link

github-actions bot commented Oct 13, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
mbedtls zephyrproject-rtos/mbedtls@85440ef zephyrproject-rtos/mbedtls#76 zephyrproject-rtos/mbedtls#76/files

DNM label due to: 1 project with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added manifest manifest-mbedtls DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Oct 13, 2025
path: modules/lib/gui/lvgl
- name: mbedtls
revision: 85440ef5fffa95d0e9971e9163719189cf34d979
revision: pull/76/head
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to know what you're pulling in the commit title (e.g. manifest: mbedtls: pull X fix) + typo: "alloacated"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pull PR 76 doesn't really give out information 🙂 One can easily trace back what PR the commit came from. I rather meant something like pull fix for [...], but anyway you'll be updating this commit later when the PR is merged.

Comment on lines 226 to +227
select MBEDTLS
select MBEDTLS_MD
select MBEDTLS_PSA_CRYPTO_C
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know #96415 is not merged yet, but are you planning to update this (and similar occurrences)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, #96415 will likely be merged before this one. Once this will be done I will update this PR accordingly. I didn't do this for now because I don't want spurious failures in the CI.

psa_set_key_type(&key_attr, PSA_KEY_TYPE_HMAC);
psa_set_key_algorithm(&key_attr, PSA_ALG_HMAC(PSA_ALG_SHA_256));
psa_set_key_usage_flags(&key_attr, PSA_KEY_USAGE_SIGN_MESSAGE);
status = psa_import_key(&key_attr, secret_key, sizeof(secret_key), &key_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if instead of importing the key every time we could just have the key ID as static in this function and import or generate it just once directly in PSA Crypto. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When should we then destroy that key? The drawback I see in doing what you are suggesting is that this key will occupy a slot in PSA core until is destroyed or the device is reset.
How often are IPv6 addresses supposed to change (with/without privacy extension)? Unless this happens quite often, having a key slot always occupied might require a larger number of key slots in the PSA core.
I'm not against the requested change, but I would like to know if you have any strong preference on this footprint/performance compromise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the RAM usage would probably be bigger because of the metadata. And the key would never be destroyed, just as the static buffer holding the key material is always reserved. No strong opinion, just food for thought, the way it's done is just not PSA-idiomatic. cc @rlubos @jukkar

@valeriosetti valeriosetti force-pushed the ipv6-replace-legacy-crypto branch from c723984 to 8759dc8 Compare October 13, 2025 09:55
@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Oct 13, 2025
@zephyrbot zephyrbot requested a review from nashif October 13, 2025 09:57
Zephyr's long term goal for crypto support is to use only PSA API. This
commit replaces usages of MD with proper PSA API for HMAC.

Signed-off-by: Valerio Setti <[email protected]>
Moving from legacy Mbed TLS crypto to PSA API caused mps2/an385
platform to fail due to stack overflow. This commit increases
the stack size to solve this problem.

Signed-off-by: Valerio Setti <[email protected]>
Include a fix for the allocated buffers in case of static key slots.
This commit will be updated once the corresponding PR is merged.

Signed-off-by: Valerio Setti <[email protected]>
@valeriosetti valeriosetti force-pushed the ipv6-replace-legacy-crypto branch from 8759dc8 to ed7a555 Compare October 13, 2025 12:36
Copy link

Copy link
Contributor

@tomi-font tomi-font left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for now, pending merging of #96415 and zephyrproject-rtos/mbedtls#76.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mbedTLS / PSA Crypto area: Networking area: Tests Issues related to a particular existing or missing test DNM (manifest) This PR should not be merged (controlled by action-manifest) manifest manifest-mbedtls

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants